import 'package:flutter/material.dart';


class MyApp03 extends StatefulWidget {
  const MyApp03({super.key});

  @override
  State<MyApp03> createState() => _MyApp03State();
}

class _MyApp03State extends State<MyApp03> {
  // 定义状态
  String name = '张三';
  int age = 18;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('有状态组件'),
        backgroundColor: Colors.pink,
      ),
      body: Center(
        child: Text('我叫$name, 今年$age'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // 改变状态
          setState(() {
            age++;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
